package com.example.controller;

import com.example.jpa.entity.Asset;
import com.example.jpa.service.AssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/api/assets")
public class AssetController {

    @Autowired
    private AssetService assetService;

    /**
     * 获取所有资产
     */
    @GetMapping("")
    public List<Asset> listAllAssets() {
        return assetService.listAllAssets();
    }

    /**
     * 根据 ID 获取资产
     */
    @GetMapping("/{id}")
    public Asset getAssetById(@PathVariable UUID id) {
        return assetService.getAssetById(id);
    }

    /**
     * 根据租户 ID 查询资产
     */
    @GetMapping("/tenant/{tenantId}")
    public List<Asset> listAssetsByTenantId(@PathVariable UUID tenantId) {
        return assetService.listAssetsByTenantId(tenantId);
    }

    /**
     * 分页查询资产
     */
    @GetMapping("/page")
    public List<Asset> listAssetsByPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return assetService.listAssetsByPage(pageNum, pageSize);
    }
}
